<template>
  <div id="agreementSearch">
    <div class="search-box">
      <el-form
        ref="ruleForm"
        :inline="true"
        :model="formInline"
        class="demo-form-inline"
      >
        <el-form-item label="协议类型" prop="type">
          <el-select v-model="formInline.type" clearable placeholder="">
            <el-option
              v-for="item in typeList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="开启状态" prop="displayed">
          <el-select v-model="formInline.displayed" clearable placeholder="">
            <el-option
              v-for="item in statusList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="展示端" prop="terminalType">
          <el-select v-model="formInline.terminalType" placeholder="请选择">
            <el-option
              v-for="item in showList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item class="s-btn">
          <el-button
            type="success"
            icon="el-icon-search"
            @click="toSearch('ruleForm')"
          >
            查询
          </el-button>
          <el-button type="success" plain @click="reset">
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
import { sysNormalDisable } from '@utils/dictionariesFunc'
import { getCreateTime } from '@utils/pubFunction'
import { getDpNum } from '@/api/system/user'

export default {
  name: 'agreementSearch',
  msg: '协议管理-顶部搜索',
  props: {
    formInline: {
      type: Object,
      default: function() {
        return {
          type: '', // 协议类型
          displayed: '', // 开启状态
          terminalType: '' // 排序
        }
      }
    }
  },
  data() {
    return {
      // 协议类型
      typeList: [{ dictLabel: '全部', dictValue: '' }],
      // 状态
      statusList: [{ dictLabel: '全部', dictValue: '' }],
      // 展示端
      showList: [{ dictLabel: '全部', dictValue: '' }]
    }
  },
  mounted() {
    this.getStatusList()
  },
  methods: {
    /* 搜索 */
    toSearch(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$emit('toSearch')
        } else {
          return false
        }
      })
    },
    async getStatusList() {
      //协议类型
      let type = await sysNormalDisable('protocol_type', 'protocol_type')
      this.typeList = this.statusList.concat(type)
      //开启状态
      let status = await sysNormalDisable(
        'protocol_displayed',
        'protocol_displayed'
      )
      this.statusList = this.statusList.concat(status)
      // 展示端
      let show = await sysNormalDisable(
        'protocol_terminal_type',
        'protocol_terminal_type'
      )
      this.showList = this.showList.concat(show)
    },
    /* 重置 */
    reset() {
      this.$refs['ruleForm'].resetFields()
    }
  }
}
</script>

<style lang="less">
#agreementSearch {
}
</style>
